﻿@{
    Layout = "";
}
@model Nop.Plugin.DiscountRules.HadSpentAmount.Models.RequirementModel
@using Nop.Web.Framework;

    <script type="text/javascript">
        $(document).ready(function () {
            $('#savehadspentamountrequirement@(Model.RequirementId)').click(function () {
                var spentAmount = $("#@Html.FieldIdFor(model => model.SpentAmount)").val();
                var discountId = @Model.DiscountId;
                var requirementId = @Model.RequirementId;
                $.ajax({
                    cache:false,
                    type: "POST",
                    url: "@(Url.Action("Configure", "DiscountRulesHadSpentAmount"))",
                    data: { "discountId": discountId, "discountRequirementId": requirementId, "spentAmount": spentAmount },
                    success: function (data) {
                         $('#pnl-save-requirement-result@(Model.RequirementId)').fadeIn("slow").delay(1000).fadeOut("slow");
                         //notify parent if it's a new requirement
                         @if (Model.RequirementId == 0)
                         {
                            <text>$("#discountRequirementContainer").trigger('nopnewdiscountruleadded', [data.NewRequirementId]);</text>
                         }
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        alert('@Html.Raw(HttpUtility.JavaScriptStringEncode(T("Admin.Promotions.Discounts.Requirements.FailedToSave").Text))');
                    }  
                });
            });
        });
    </script>
    
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.SpentAmount):
            </td>
            <td class="adminData">
                <div>@Html.EditorFor(model => model.SpentAmount) <input type="button" id="savehadspentamountrequirement@(Model.RequirementId)" class="k-button" value="@T("Admin.Common.Save")" /></div>
                <div id="pnl-save-requirement-result@(Model.RequirementId)" style="display:none;">@T("Admin.Promotions.Discounts.Requirements.Saved")</div>
            </td>
        </tr>
    </table>